package com.servlet;

import com.admin.Action;
import com.admin.ActionFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AdminBaseServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding(this.getInitParameter("req"));
        resp.setContentType(this.getInitParameter("resp"));

        String uri = req.getRequestURI();
        String path = this.getServletContext().getContextPath();
        uri = uri.replaceAll(path + "/", "");
        uri = uri.substring(0, uri.length() - (uri.length() - uri.indexOf(".")));

        Action action = null;
        System.out.println(uri);
        action = ActionFactory.getAction(uri);

        action.execute(req, resp);

    }
}
